/*
 * This program is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this 
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 
 * or from the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright 2008 Pentaho Corporation.  All rights reserved.
 *
 * @author Will Gorman (wgorman@pentaho.com)
 */
package org.pentaho.actioneditor.client.actionpanels;

import org.pentaho.actioneditor.client.ActionEditor;
import org.pentaho.actionsequence.dom.IActionInputVariable;
import org.pentaho.actionsequence.dom.actions.JFreeReportAction;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Widget;

public class JFreeReportActionPanel extends AbstractActionPanel {
  final JFreeReportActionUI aui = new JFreeReportActionUI();
  JFreeReportAction action;
  
  public JFreeReportActionPanel(JFreeReportAction action, ActionEditor actionEditor) {
    this.action = action;
    this.actionEditor = actionEditor;
  }
  
  public void init() {
    aui.setAddParameterCommand(new JFreeReportActionUI.ItemCommand() {

      public void execute(String text) {
        // TODO Auto-generated method stub
        
      }
      
    });
    
    aui.setAddSubreportCommand(new JFreeReportActionUI.ItemCommand() {

      public void execute(String text) {
        // TODO Auto-generated method stub
        
      }
      
    });
    
    aui.init();
    
    aui.getName().setText(action.getDescription());
    aui.getName().addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        action.setDescription(aui.getName().getText());
        item.setText(aui.getName().getText());
      }
    });
    
    aui.getReportSpec().setText(action.getDescription());
    aui.getReportSpec().addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        action.setReportDefinition((IActionInputVariable)JFreeReportActionPanel.this.getProviderFromString(aui.getReportSpec().getText()));
      }
    });
    
    aui.getReportData().setText(action.getDescription());
    aui.getReportData().addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        action.setData(JFreeReportActionPanel.this.getProviderFromString(aui.getReportData().getText()));
      }
    });
    
    aui.getReportFormat().setText(action.getDescription());
    aui.getReportFormat().addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        action.setOutputType(JFreeReportActionPanel.this.getProviderFromString(aui.getReportFormat().getText()));
      }
    });
    
    aui.getOutputName().setText(action.getDescription());
    aui.getOutputName().addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        action.setOutputReport(aui.getOutputName().getText());
      }
    });
  }
  
  public Widget getRoot() {
    return aui.getRoot();
  }
}
